﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using LastLandClient.Data;

using Up2Link.SegString;

namespace LastLandClient.Core.CmdInterpreter
{
    public class CCmdMove : ICommandInterpreter
    {
        public void ExecuteCommand(string _cmd, string _args)
        {
            if (_args != null)
            {
                String[] args = _args.Split(CConst.DELIMITER_ARGUMENT);
                if (args.Length == 1 && CData.clientConnected)
                {
                    String arg = args[0].ToLowerInvariant().Trim();
                    Int32 msgCode = 0;
                    switch (arg)
                    {
                        case "east":
                            msgCode = CConst.CLIENT_MESSAGE_MOVE_EAST;
                            break;
                        case "south":
                            msgCode = CConst.CLIENT_MESSAGE_MOVE_SOUTH;
                            break;
                        case "west":
                            msgCode = CConst.CLIENT_MESSAGE_MOVE_WEST;
                            break;
                        case "north":
                            msgCode = CConst.CLIENT_MESSAGE_MOVE_NORTH;
                            break;
                        default:
                            break;
                    }

                    if (msgCode != 0)
                    {
                        CMessageSS moveMsg = new CMessageSS(msgCode, 0, CMessageSS.ENCODING_UTF32, "");
                        CData.client.Send(moveMsg);
                    }
                    else
                    {
                        CData.console.SendOutput("参数" + arg + "无效");
                        CData.console.SendOutput("move:east|west|north|south");
                    }
                }
                else if (args.Length != 1)
                {
                    CData.console.SendOutput("move指令接受一个参数");
                }
                else if (!CData.clientConnected)
                {
                    CData.console.SendOutput("玩家尚未连接服务器");
                }
                else
                {
                    CData.console.SendOutput("无效的指令");
                }
            }
            else
            {
                CData.console.SendOutput("无效的指令");
            }
        }
    }
}
